#include <stdio.h>  
#include <mkl_lapacke.h>  
#include <mkl.h>  

#pragma comment(lib,"mkl_lapack95_lp64.lib")
#pragma comment(lib,"mkl_rt.lib")

int I(int x, int y)
{
	return x*3+y;
}

int main(void){  
	double superb[200];    
	lapack_int m = 3, n = 3;
	double A[] = {-6,-8,52,
				10,-41,27,
				-32,201,-7};
	
	double s[3];  
	double v[3*3];  
	double u[3*3];

	lapack_int ldu = 3, ldvt = 3, lda=3;    

	LAPACKE_dgesvd( LAPACK_ROW_MAJOR, 'A', 'A', m, n, A, lda,    
		s, u, ldu, v, ldvt, superb );

	for (int i=0;i<3;i++)
	{
		for (int j=0;j<3;j++)
		{
			printf("%f ",v[i*3+j]);
		}
		printf("\n");
	}

	printf("s = %f %f %f\n",s[0],s[1],s[2]);  

	double result[3][3];
	double output[3][3];

	for (int i=0;i<3;i++)
	{
		for (int j=0;j<3;j++)
		{
			result[i][j]=u[I(i,j)]*s[j];
		}
	}

	for (int i=0;i<3;i++)
	{
		for (int j=0;j<3;j++)
		{
			double sum=0;
			for (int k=0;k<3;k++)
			{
				sum+=result[i][k]*v[I(k,j)];
			}
			output[i][j]=sum;
		}
	}

	for (int i=0;i<3;i++)
	{
		for (int j=0;j<3;j++)
		{
			printf("%f ",output[i][j]);
		}
		printf("\n");
	}
}  